import request from "@/api";
import { BaseRet, PageQuery, PageRet } from "../../response";
import { AxiosPromise } from "axios";

export default class EmailAccountApi {
  /**
   * 查询
   * @returns
   */
  static async query(data: EmailAccountQuery): Promise<PageRet<EmailAccountModel>> {
    return await request({
      url: "/emailAccount/query",
      method: "post",
      data: data,
    });
  }

  /**
   * 新增
   * @returns
   */
  static async create(data: EmailAccountEdit): Promise<BaseRet> {
    return await request({
      url: `/emailAccount/create`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改
   * @returns
   */
  static async update(data: EmailAccountEdit): Promise<BaseRet> {
    return await request({
      url: `/emailAccount/update`,
      method: "put",
      data: data,
    });
  }

  /**
   * 删除
   * @returns
   */
  static async delete(id: string): Promise<BaseRet> {
    return await request({
      url: `/emailAccount/delete/${id}`,
      method: "delete",
    });
  }

  /**
   * 模板选择账户下拉框数据
   * @returns
   */
  static async queryAccountSelect(): Promise<EmailAccountSelect[]> {
    return await request({
      url: `/emailAccount/QueryAccountSelect`,
      method: "get",
    });
  }

  /**
   * 导出
   * @returns
   */
  static async exportExcel() {
    return await request({
      url: `/emailAccount/ExportExcel`,
      responseType: "arraybuffer",
      method: "get",
    });
  }

  /**
   * 导入
   * @returns
   */
  static async importExcel(file: any): Promise<BaseRet> {
    return await request({
      url: `/emailAccount/ImportExcel`,
      headers: { "Content-Type": "multipart/form-data" },
      method: "post",
      data: { file: file },
    });
  }
}

export interface EmailAccountModel {
  id: string;
  email: string;
  displayName: string;
  host: string;
  port: number;
  username: string;
  password: string;
  enableSsl: boolean;
  useDefaultCredentials: boolean;
}

export interface EmailAccountQuery extends PageQuery {
  searchString: string;
}

export interface EmailAccountEdit {
  id?: string;
  email?: string;
  displayName?: string;
  host?: string;
  port?: number;
  username?: string;
  password?: string;
  enableSsl?: boolean;
  useDefaultCredentials?: boolean;
}

export interface EmailAccountSelect {
  id?: string;
  email?: string;
}
